<template>
  <div>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm"  label-width="80px">
    <el-form-item label="收货名" prop="receiverName">
      <el-input v-model="dataForm.receiverName" placeholder="收货名"></el-input>
    </el-form-item>
    <el-form-item label="收货电话" prop="receiverPhone">
      <el-input v-model="dataForm.receiverPhone" placeholder="收货电话"></el-input>
    </el-form-item>
    <el-form-item label="收货地址" prop="receiverDetailAddr">
      <el-input v-model="dataForm.receiverDetailAddr" placeholder="收货地址"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeForm">取消</el-button>
      <el-button type="primary" @click="submitForm">确定</el-button>
    </span>
  </div>
</template>

<script>
	import addressAPI from '../api/address.js'
	import {
		mapGetters
	} from "vuex";
	
  export default {
    data () {
      return {
        
        dataForm: {
          receiverId: this.$store.getters.getUser.userId,
          receiverName: '',
          receiverPhone: '',
          receiverDetailAddr: ''
        },
        dataRule: {
          receiverId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          receiverName: [
            { required: true, message: '收货名不能为空', trigger: 'blur' }
          ],
          receiverPhone: [
            { required: true, message: '收货电话不能为空', trigger: 'blur' }
          ],
          receiverDetailAddr: [
            { required: true, message: '收货地址不能为空', trigger: 'blur' }
          ],
          gmtCreate: [
            { required: true, message: '创建日期不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '修改日期不能为空', trigger: 'blur' }
          ]
        }
      }
    },
		computed:{
			...mapGetters(["getUser","getNum"])
		},
    methods: {
      
      // 表单提交
      submitForm () {
        this.$emit('closeAddressDialog')
				addressAPI.addAddress(this.dataForm).then(({data}) => {
          this.$message({
            message: '添加成功！',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.$emit('refreshDataList')//这行是刷新父页面的，但是你父页面我没给你定义这个东西，怕整乱了你的东西
            }
          })
        })
      },
			closeForm() {
				 this.$emit('closeAddressDialog')
			}
    }
  }
</script>
